package com.pearl.actuator.demo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.endpoint.annotation.WriteOperation;
import org.springframework.boot.actuate.endpoint.web.annotation.WebEndpoint;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

/**
 * @author TangDan
 * @version 1.0
 * @since 2023/5/23
 */
@WebEndpoint(id = "envActive")
@Component
public class JdKEnvWebEndpoint{

    @Autowired
    private Environment environment;

/*
    @ReadOperation
    public Map<String,String> getEnvActive() {
        Map<String,String> result = new HashMap<>();
        result.put("java.version",environment.getProperty("java.version"));
        result.put("java.home",environment.getProperty("java.home"));
        return result;
    }
*/

    // 读操作，对应GET请求
/*    @ReadOperation
    public Map<String,String> getEnvActive(String param) {
        Map<String,String> result = new HashMap<>();
        result.put("java.version",environment.getProperty("java.version"));
        result.put("java.home",environment.getProperty("java.home"));
        result.put("param",param);
        return result;
    }*/

    @WriteOperation
    public String getEnvActive(String name) {
        return name;
    }
}